package view;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class MainFrame extends javax.swing.JFrame
{

    private String userName;

    public MainFrame(String userName)
    {
        this.userName = userName;
        this.setTitle("Hotel Management System 1.0");
        this.setSize(1000, 700);
        this.setLayout(null);
        ImageIcon ic = new ImageIcon(LoginDialog.class.getResource("/data/icon.png"));
        this.setIconImage(ic.getImage());
        this.setResizable(false);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private void Hide()
    {
        this.dispose();
    }

    public void Show(int code)
    {
        if (code == 1)
        {
            MenuAdminPanel menu = new MenuAdminPanel(this);
            menu.Show();
        }
        else
        {
            MenuPanel menu = new MenuPanel(this);
            menu.Show();
        }
        JLabel lbLogin = new JLabel();
        lbLogin.setFont(new java.awt.Font("SansSerif", 0, 13)); // NOI18N
        lbLogin.setForeground(new java.awt.Color(0, 51, 153));
        lbLogin.setText("Bạn đang đăng nhập bằng tài khoản \"" + userName + "\"");
        lbLogin.setBounds(600, 5, 285, 25);
        this.add(lbLogin);

        JButton btnLogout = new JButton();
        btnLogout.setBounds(900, 5, 85, 25);
        btnLogout.setText("Đăng xuất");
        btnLogout.addActionListener(new java.awt.event.ActionListener()
        {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                Hide();
                LoginDialog lDialog = new LoginDialog(null, true);
            }
        });
        this.add(btnLogout);
        this.setLocationRelativeTo(null);//xuất hiện giữa màn hình
        this.setVisible(true);
        this.setEnabled(true);

    }
}
